package com.ht.demo.admin.controller.monitor;

import com.ht.demo.common.appexception.AppException;
import com.ht.demo.common.appexception.ResultData;
import com.ht.demo.common.enums.OperateTypeEnum;
import com.ht.demo.common.page.PageBO;
import com.ht.demo.common.pojo.bo.monitor.SysLoggerBO;
import com.ht.demo.common.pojo.qto.monitor.SysLoggerQTO;
import com.ht.demo.service.annotation.LoggerInfo;
import com.ht.demo.service.annotation.Permission;
import com.ht.demo.service.manager.monitor.SysLoggerManager;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author hdengxian
 * @Date 2023/5/30 16:23
 */
@RestController
@RequestMapping("${basePath}")
public class SysLoggerController {
    @Resource
    private SysLoggerManager sysLoggerManager;

    @Permission(permissionId = "monitor:operlog:remove", desc = "删除操作日志")
    @DeleteMapping("/monitor/log/{sysLoggerIds}")
    public ResultData<Boolean> deleteLog(@PathVariable Long[] sysLoggerIds) throws AppException {
        return new ResultData<>(sysLoggerManager.deleteLog(sysLoggerIds));
    }

    @Permission(permissionId = "monitor:operlog:remove", desc = "删除操作日志")
    @LoggerInfo(title = "日志管理-清空所有日志", operateType = OperateTypeEnum.DELETE)
    @DeleteMapping("/monitor/log/clean")
    public ResultData<Boolean> cleanLog() throws AppException {
        return new ResultData<>(sysLoggerManager.deleteLog(null));
    }

    @GetMapping("/monitor/log/list")
    public ResultData<PageBO<SysLoggerBO>> findLoggerForPage(SysLoggerQTO qto) throws AppException {
        return new ResultData<>(sysLoggerManager.findLoggerForPage(qto));
    }
}
